"""

"""

from kivy.uix.screenmanager import Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.app import App
from ..components.settings_panel import AppSettingsPanel

class SettingsWindow(Screen):
    """"""
    
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self._build_ui()
    
    def _build_ui(self):
        """"""
        main_layout = BoxLayout(
            orientation='vertical',
            spacing=20,
            padding=20
        )
        
        # 
        title = Label(
            text="Settings",
            font_size=48,
            size_hint_y=None,
            height=80,
            bold=True,
            color=(0.2, 0.6, 0.9, 1)
        )
        main_layout.add_widget(title)
        
        # 
        self.settings_panel = AppSettingsPanel()
        main_layout.add_widget(self.settings_panel)
        
        # 
        button_layout = BoxLayout(
            orientation='horizontal',
            size_hint_y=None,
            height=50,
            spacing=10
        )
        
        # 
        back_btn = Button(
            text="Back",
            size_hint_x=0.3,
            font_size=24,  # 放大字体
            height=60
        )
        back_btn.bind(on_press=self._go_back)
        button_layout.add_widget(back_btn)
        
        # 
        apply_btn = Button(
            text=" Apply Settings",
            size_hint_x=0.4
        )
        apply_btn.bind(on_press=self._apply_settings)
        button_layout.add_widget(apply_btn)
        
        # 
        about_btn = Button(
            text="About",
            size_hint_x=0.3,
            font_size=24,  # 放大字体
            height=60
        )
        about_btn.bind(on_press=self._show_about)
        button_layout.add_widget(about_btn)
        
        main_layout.add_widget(button_layout)
        
        self.add_widget(main_layout)
    
    def on_enter(self):
        """"""
        app = App.get_running_app()
        
        # 
        if hasattr(app, 'settings_data'):
            self.settings_panel.set_settings(app.settings_data)
    
    def _go_back(self, instance):
        """"""
        app = App.get_running_app()
        app.navigate_to('main')
    
    def _apply_settings(self, instance):
        """"""
        app = App.get_running_app()
        
        # 
        settings = self.settings_panel.get_settings()
        app.update_settings(settings)
        
        print("Settings applied:", settings)
        
        # 
        app.navigate_to('main')
    
    def _show_about(self, instance):
        """"""
        # TODO: 
        print("About Local Smart Video Summary Tool")
        print("Version: 1.0.0")
        print("Author: Open Source Community")
        print("License: MIT License")